#!/usr/bin/python
import re

class Mt_db(object):
	def __init__(self, func):
		self.cnt=0;
		self.start=0;
		self.function = func;
		self.val = 0;
		self.duration=0;
	def set_db_val(self, start, val):
		self.start = start
		self.val   = val

class Mt_thread_db(object):
	def __init__(self):
		counter=0
		self.mt_db = {}
	def get_db_object(self, func):
		try:
			_t = self.mt_db[func]
			return _t
		except:
			print "Unable to locate function "+func
			self.mt_db[func] = Mt_db(func)
			return self.mt_db[func]
	def sublimate(self, db_obj, func, val):
		print "sublimate"
	def process_data(self, start, func, val):
		_t = get_db_object(func)
		if start:
			print "Creating New DB Object"
			_t = _t.set_db_val(start, func, val)
		else:
			self.sublimate(_t, func, val)
			self.mt_db.append(_t)
			

class Mt_parser(object):
	def __init__(self):
		self.counter=0
		self.thread_db = {}
		print "Init"
	def main(self):
		print"MT PARSER"
		self.parser("dump.log");
	def get_thread_obj(self, thread):
		try:
			return self.thread_db[thread];
		except:	
			print "Creating New Thread for "+thread
			self.thread_db[thread]=Mt_thread_db()
	def process_line(self, line):
		line.strip()	
		re.split('(\s+)', line)
		t=line.split(' ')
		print t
		start = t[0]
		thread = t[1]
		func = t[2]
		val = t[3].strip()
		print start,thread,func,val
		thread_obj = self.get_thread_obj(thread)
		thread_obj.process_data(start, func, val)
	def parser(self, filename):
		f = open(filename, 'r')
		f.readline();
		for line in f:
			print line
			self.process_line(line)
		

if __name__ == '__main__':
	s_ = Mt_parser();
	s_.main()
